package com.app.newcsc.fragment.orderdetail;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;

import com.app.newcsc.BR;
import com.app.newcsc.R;
import com.app.newcsc.app.AppApplication;
import com.app.newcsc.app.AppViewModelFactory;
import com.app.newcsc.app.Constants;
import com.app.newcsc.databinding.FragmentOrderDetailBinding;
import com.app.newcsc.entity.Message;
import com.app.newcsc.entity.TransactionOrderEntity;
import com.app.newcsc.entity.TransactionPlanEntity;
import com.app.newcsc.utils.CallPhoneUtil;
import com.app.newcsc.utils.ClipeBoardUtil;
import com.app.newcsc.utils.GlideUtils;
import com.app.newcsc.utils.NumberUtils;
import com.app.newcsc.utils.TextUtil;
import com.app.newcsc.utils.ToastUtil;
import com.app.newcsc.utils.Utils;
import com.app.newcsc.view.CustomPopWindow;
import com.app.newcsc.view.InputPwdDialog;
import com.app.newcsc.view.MCheckBox;
import com.lwkandroid.imagepicker.ImagePicker;
import com.lwkandroid.imagepicker.data.ImageBean;
import com.lwkandroid.imagepicker.data.ImageContants;
import com.lwkandroid.imagepicker.data.ImagePickType;
import com.lwkandroid.imagepicker.ui.grid.view.ImageDataActivity;
import com.lwkandroid.imagepicker.utils.GlideImagePickerDisplayer;
import com.tbruyelle.rxpermissions2.Permission;
import com.tbruyelle.rxpermissions2.RxPermissions;

import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import me.goldze.mvvmhabit.base.BaseFragment;
import me.goldze.mvvmhabit.bus.RxBus;
import me.goldze.mvvmhabit.bus.RxSubscriptions;

/**
 * @author: woking
 * @date: 2021/6/17
 * @description：
 */
public class OrderDetailFragment extends BaseFragment<FragmentOrderDetailBinding, OrderDetailViewModel> {
    private boolean isOrder = true;
    private TransactionPlanEntity mOrderDetailEntity;
    private TransactionPlanEntity.OrdersData mOrdersData;
    private TransactionOrderEntity.SellerPay dataSellerPay;
    private TransactionOrderEntity mTransactionOrderEntity;
    private Disposable mSubscription;
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_order_detail;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }
    @Override
    public OrderDetailViewModel initViewModel() {
        //使用自定义的ViewModelFactory来创建ViewModel，如果不重写该方法，则默认会调用NetWorkViewModel(@NonNull Application application)构造方法
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this, factory).get(OrderDetailViewModel.class);
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        if(mSubscription != null)
        {
            RxSubscriptions.remove(mSubscription);
        }
    }
    @Override
    public void initData() {
        super.initData();
        if (getArguments() != null) {
            isOrder = getArguments().getBoolean("isOrder");
            if(isOrder)
            {
                mOrderDetailEntity = (TransactionPlanEntity)getArguments().getSerializable("entity");
            }
            else
            {
                mOrdersData = (TransactionPlanEntity.OrdersData)getArguments().getSerializable("entity");
            }
        }
        if(isOrder && mOrderDetailEntity != null)
        {
            viewModel.otcBuyShowOrder(mOrderDetailEntity.id+"");//订单
        }
        else if(mOrdersData != null)
        {
//            viewModel.otcPlanOrderDetail(mOrdersData.id+"");//挂单
            viewModel.otcBuyShowOrder(mOrdersData.id+"");//订单
        }
        binding.ivTitleBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getActivity().finish();
            }
        });
//        if(isOrder && mOrderDetailEntity != null && mOrderDetailEntity.status == 0)//订单
//        if(mOrderDetailEntity.status == 0)//订单
//        {
            binding.shouKuanFangshiRl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    selectPayType(view);
                }
            });
//        }
        isOrder = true;
        viewModel.mTransactionOrderEntity.observe(this, new Observer<TransactionOrderEntity>() {
            @Override
            public void onChanged(TransactionOrderEntity transactionOrderEntity) {
//                Log.e("TAG",transactionOrderEntity.seller.data.realname + "======seller====================onChanged=========buyer===="+transactionOrderEntity.buyer.data.nickname+"  "+transactionOrderEntity.sellerPays.data.get(0).account);
                mTransactionOrderEntity = transactionOrderEntity;
                initOrderDetail(transactionOrderEntity);
            }
        });
        viewModel.mTransactionOrderGuaDanEntity.observe(this, new Observer<TransactionOrderEntity>() {
            @Override
            public void onChanged(TransactionOrderEntity entity) {
//                Log.e("TAG",entity.seller.data.realname + "======seller====================onChanged=========buyer===="+entity.buyer.data.nickname+"  "+entity.sellerPays.data.get(0).account);
                mTransactionOrderEntity = entity;
                initOrderDetail(entity);
            }
        });

        mSubscription = RxBus.getDefault().toObservable(Message.class)
                .observeOn(AndroidSchedulers.mainThread()) //回调到主线程更新UI
                .subscribe(new Consumer<Message>() {
                    @Override
                    public void accept(final Message message) throws Exception {
                        if(message.getName().equals("upload_finish"))
                        {
                            getActivity().finish();
                        }
                    }
                });
        //将订阅者加入管理站
        RxSubscriptions.add(mSubscription);
    }

    private void initOrderDetail(TransactionOrderEntity entity)
    {
//        binding.priceTv.setText("¥" + NumberUtils.keepPrecision((Double.parseDouble(entity.price) * Double.parseDouble(entity.num)),4));
        binding.priceTv.setText(AppApplication.pricetag + NumberUtils.keepPrecision((Double.parseDouble(entity.price) * Double.parseDouble(entity.num)),4)
        /*+"  (折合CNY￥" +NumberUtils.keepPrecision((Double.parseDouble(entity.price) * Double.parseDouble(entity.num)*7),4)+ ")"*/);
//            entity.type 1求购  2转增
        binding.shouKuanRenTv.setText(entity.type == 1 ? entity.seller.data.nickname : entity.buyer.data.nickname);//收款人昵称
//        binding.shouKuanRenRealTv.setText(entity.type == 1 ? entity.seller.data.realname : entity.buyer.data.realname);//收款人实名
        if(entity.type == 2)
        {
            binding.shpukuanrenNichengTv.setText("买家昵称");
        }

        binding.shouKuanRenTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ClipeBoardUtil.setClipeBoardContent(getContext(), binding.shouKuanRenTv.getText().toString());
                ToastUtil.showToast("复制成功");
            }
        });

        binding.shouKuanRenRealTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ClipeBoardUtil.setClipeBoardContent(getContext(), binding.shouKuanRenRealTv.getText().toString());
                ToastUtil.showToast("复制成功");
            }
        });
        setPayType(entity,entity.pay_types.get(0));
//        binding.shouKuanIdnoTv.setText(entity.pay_card);//收款账号
//        if(dataSellerPay != null)
//        {
//            binding.shouKuanIdnoTv.setText(TextUtil.isEmpty(entity.pay_card) ? dataSellerPay.account: entity.pay_card);//收款账号
//        }
//        else
//        {
//            if(entity != null && entity.sellerPays != null && entity.sellerPays.data.size() > 0)
//            {
//                setPayType(entity,entity.sellerPays.data.get(0).type);
//            }
//        }
        binding.shouKuanIdnoTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ClipeBoardUtil.setClipeBoardContent(getContext(), binding.shouKuanIdnoTv.getText().toString());
                ToastUtil.showToast("复制成功");
            }
        });
        binding.fukuanImg.setOnClickListener(new View.OnClickListener() {//付款截图
            @Override
            public void onClick(View view) {
                if(!TextUtil.isEmpty(entity.pay_card) && !TextUtil.isEmpty(entity.img_url))
                {
                    popFuKuan(view,entity.img_url);
                    return;
                }
                if(dataSellerPay != null && dataSellerPay.type != 1)
                {
                    popFuKuan(view,dataSellerPay.image);
                }
            }
        });
        binding.orderNoTv.setText(entity.identifier+"");//订单号
        binding.orderNoTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ClipeBoardUtil.setClipeBoardContent(getContext(), binding.orderNoTv.getText().toString());
                ToastUtil.showToast("复制成功");
            }
        });
        binding.orderPhoneTv.setText(entity.type == 1 ? entity.seller.data.mobile : entity.buyer.data.mobile);//联系电话
        binding.orderPhoneTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (TextUtils.isEmpty(binding.orderPhoneTv.getText().toString())) {
                    return;
                }
                CallPhoneUtil.diallPhone(getActivity(), binding.orderPhoneTv.getText().toString());
            }
        });
        binding.orderTimeTv.setText(entity.createtime+"");//下单时间
        if(isOrder)
        {
            //订单状态:0=待支付,1=待确认,2=确认成功,3=订单关闭,4=仲裁 5 待审核
            if(entity.status == 0 && entity.type == 1)//求购   买家确认上传
            {
                binding.tvQueren.setBackgroundResource(R.drawable.shape_radius_5_1fabcc_3212cf);
                binding.tvQueren.setEnabled(true);
            }
            else if(entity.status == 1 && entity.type == 2)//转赠   卖家确认订单
            {
//                binding.orderTimeTv.setBackgroundResource(R.color.my_color_cccccc);
                binding.tvQueren.setBackgroundResource(R.drawable.shape_radius_5_1fabcc_3212cf);
                binding.tvQueren.setEnabled(true);
            }
        }

        binding.tvQueren.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(!Utils.isLogin())
                {
                    return;
                }
                if(isOrder)
                {
                    //订单状态:0=待支付,1=待确认,2=确认成功,3=订单关闭,4=仲裁 5 待审核
                    if(entity.status == 0 && entity.type == 1)//请付款 求购   买家确认上传
                    {
                        Bundle bundle = new Bundle();
                        bundle.putSerializable("entity",entity);
                        bundle.putString("title", "上传截图");
                        startContainerActivity(OrderDetailUploadFragment.class.getCanonicalName(),bundle);//买家确认上传
                    }
                    else if(entity.status == 1 && entity.type == 2)//转赠   卖家确认订单
                    {
                        getMemberBaseInfo(entity);//卖家 确认订单
                    }

//                    Bundle bundle = new Bundle();
//                    bundle.putSerializable("entity",entity);
//                    bundle.putString("title", "上传截图");
//                    startContainerActivity(OrderDetailUploadFragment.class.getCanonicalName(),bundle);//买家确认上传
                }
            }
        });
//        binding.tvZhongcai.setVisibility(View.VISIBLE);
        binding.tvZhongcai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(!Utils.isLogin())
                {
                    return;
                }
                Bundle bundle = new Bundle();
                bundle.putSerializable("entity",entity);
                bundle.putString("title", "申请仲裁");
                startContainerActivity(OrderDetailUploadFragment.class.getCanonicalName(),bundle);
            }
        });
        binding.orderStatusTv.setText(setStatus(entity));

//        binding.tvQueren.setBackgroundResource(R.drawable.shape_radius_5_1fabcc_3212cf);
//        binding.tvQueren.setEnabled(true);
    }
    public String setStatus(TransactionOrderEntity entity)
    {
        String status = "完成";

        //            binding.tip1Tv.setText("如您已向卖家转账付款，请务必点击下方“我已付款”按钮，否则有可能造成资金损失");
//            binding.tip2Tv.setText("*请在规定2小时内付款，超时订单自动提交，交易中出现问题可以申请仲裁");
//            binding.tip3Tv.setText("*转账时请备注订单号");
        //订单状态:0=待支付,1=待确认,2=确认成功,3=订单关闭,4=仲裁 5 待审核
        switch (entity.status)
        {
            case 0:
                status = entity.type == 1 ? "请付款" : "待付款";
//                binding.tvQueren.setEnabled(true);
                binding.tvQueren.setText("我已付款");
                if(entity.type != 1)
                {
                    binding.tvQueren.setText("待对方付款");
                }

                binding.fukuanNameTv.setText("收款码");
                binding.paytypeImg.setVisibility(View.VISIBLE);
                binding.tip2Tv.setText("* 请在规定2小时内收款，交易中出现问题可以申请仲裁");
                if(!isOrder)
                {
                    status = "请付款";
                    binding.tvQueren.setText("待付款");
                    if(entity.type == 2)//卖出
                    {
                        binding.tip3Tv.setVisibility(View.GONE);
                        binding.tip2Tv.setText("* 请在规定2小时内收款，交易中出现问题可以申请仲裁");

                        binding.shpukuanrenNichengTv.setText("买家昵称");
                        binding.shouKuanRenTv.setText(entity.buyer.data.nickname);//收款人昵称
                        binding.shouKuanShimingRl.setVisibility(View.GONE);
                        binding.paytypeKeyTv.setText("类型");
                        binding.shouKuanJietuRl.setVisibility(View.GONE);
                    }
                    else
                    {
                        binding.fukuanNameTv.setText("收款码");
                    }
                }
                break;
            case 1:
                status = "等待卖家确认收款";
                binding.tvQueren.setText("待确认");
//                binding.tvZhongcai.setVisibility(View.VISIBLE);
                if(entity.type == 2)//卖出
                {
                    binding.tvZhongcai.setVisibility(View.VISIBLE);
                    binding.tip3Tv.setVisibility(View.VISIBLE);
                    binding.tip2Tv.setText("* 需在3小时之内确认放行，否则订单自动确认通过");
                }
                break;
            case 2:
                status = "交易成功";
                binding.tvQueren.setEnabled(false);
                binding.tvQueren.setText("完成");
//                    binding.shouKuanFangshiRl.setVisibility(View.GONE);
//                    binding.shouKuanIdnoRl.setVisibility(View.GONE);
//                    binding.shouKuanJietuRl.setVisibility(View.GONE);
                if(!isOrder)
                {
                    status = "交易成功";
                    binding.tvQueren.setText("完成");
                    if(entity.type == 2)//卖出
                    {
                        binding.shpukuanrenNichengTv.setText("买家昵称");
                        binding.shouKuanRenTv.setText(entity.buyer.data.nickname);//收款人昵称
                        binding.shouKuanShimingRl.setVisibility(View.GONE);
                        binding.paytypeKeyTv.setText("类型");

                        binding.tip3Tv.setVisibility(View.GONE);
                        binding.tip2Tv.setText("* 请在规定2小时内收款，交易中出现问题可以申请仲裁");
                    }
                }
                break;
            case 3:
                status = "订单关闭";
                binding.tvQueren.setEnabled(false);
                binding.tvQueren.setText("关闭");
                if(!isOrder)
                {
                    status = "订单关闭";
                    binding.tvQueren.setText("关闭");
                    if(entity.type == 2)//卖出
                    {
                        binding.tip3Tv.setVisibility(View.GONE);
                        binding.tip2Tv.setText("* 请在规定2小时内收款，交易中出现问题可以申请仲裁");

                        binding.shpukuanrenNichengTv.setText("买家昵称");
                        binding.shouKuanRenTv.setText(entity.buyer.data.nickname);//收款人昵称
                        binding.shouKuanShimingRl.setVisibility(View.GONE);
                        binding.shouKuanFangshiRl.setVisibility(View.GONE);
                        binding.shouKuanIdnoRl.setVisibility(View.GONE);
                        binding.shouKuanJietuRl.setVisibility(View.GONE);
                    }
                    else
                    {
                        binding.shouKuanFangshiRl.setVisibility(View.GONE);
                        binding.shouKuanIdnoRl.setVisibility(View.GONE);
                        binding.shouKuanJietuRl.setVisibility(View.GONE);
                    }
                }
                break;
            case 4:
                status = "仲裁中";
                binding.tvQueren.setEnabled(false);
                binding.tvQueren.setText("仲裁中");
                break;
            case 5:
                status = "待审核";
                binding.tvQueren.setEnabled(false);
                binding.tvQueren.setText("待审核");
                if(!isOrder)
                {
                    status = "待审核";
                    binding.tvQueren.setText("待审核");
                    if(entity.type == 2)//卖出
                    {
                        binding.shpukuanrenNichengTv.setText("买家昵称");
                        binding.shouKuanRenTv.setText(entity.buyer.data.nickname);//收款人昵称
                        binding.shouKuanShimingRl.setVisibility(View.GONE);
                        binding.paytypeKeyTv.setText("类型");

                        binding.tip3Tv.setVisibility(View.GONE);
                        binding.tip2Tv.setText("* 请在规定2小时内收款，交易中出现问题可以申请仲裁");
                    }
                }
                break;
        }
        return status;
    }
    private void setPayType(TransactionOrderEntity entity,int type)
    {
        if(type == 0)
            type = 1;
        dataSellerPay = getSellerPay(entity,type+"");
        if(type == 1)
        {
            binding.paytypeTv.setText("银行卡");//收款方式
        }
        else if(type == 2)
        {
            binding.paytypeTv.setText("支付宝");
        }
        else if(type == 3)
        {
            binding.paytypeTv.setText("微信");
        }
        if(dataSellerPay != null)
        {
            binding.shouKuanIdnoTv.setText(dataSellerPay.account);
            binding.shouKuanRenRealTv.setText(dataSellerPay.name);//收款人实名
        }
    }
    private void setPayType(TransactionOrderEntity entity,String type)
    {
        dataSellerPay = getSellerPay(entity,type);
        if(dataSellerPay != null)
        {
            if(dataSellerPay.type == 1)
            {
                binding.paytypeTv.setText("银行卡");//收款方式
            }
            else if(dataSellerPay.type == 2)
            {
                binding.paytypeTv.setText("支付宝");
            }
            else if(dataSellerPay.type == 3)
            {
                binding.paytypeTv.setText("微信");
            }
            binding.shouKuanIdnoTv.setText(dataSellerPay.account);
            binding.shouKuanRenRealTv.setText(dataSellerPay.name);//收款人实名
        }
    }
    public TransactionOrderEntity.SellerPay getSellerPay(TransactionOrderEntity entity,String typeStr)
    {
        if(entity != null && entity.sellerPays != null && entity.sellerPays.data.size() > 0)
        {
            try {
                if(TextUtil.isEmpty(typeStr))
                {
                    return entity.sellerPays.data.get(0);
                }
                int type = Integer.parseInt(typeStr);

                for(int i = 0; i < entity.sellerPays.data.size(); i++)
                {
                    TransactionOrderEntity.SellerPay data = entity.sellerPays.data.get(i);
                    if(type == data.type)
                    {
                        return data;
                    }
                }
            } catch (NumberFormatException e) {
                e.printStackTrace();
                return entity.sellerPays.data.get(0);
            }
        }
        return null;
    }

    private InputPwdDialog inputPasswordDialog;
    private void getMemberBaseInfo(TransactionOrderEntity entity) {
        inputPasswordDialog = new InputPwdDialog(getContext(), new InputPwdDialog.InputPasswordListener() {
            @Override
            public void callbackPassword(String password) {
//                Log.e("TAG","====states====callbackPassword=====password=="+password);
                viewModel.otcBuyConfirm(entity.id+"" , password);;
            }
        });
        inputPasswordDialog.setOnDismissListener(dialog -> {

        });
        inputPasswordDialog.show();
    }


    private int code;
    public void selectPictur()
    {
        code = Constants.INTENT_REQUESTCODE_VERIFIED_IMG1;
//        closeKeyBoard();
        new RxPermissions(this).requestEach(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
                .subscribe(new Consumer<Permission>() {
                    @Override
                    public void accept(Permission permission) throws Exception {
                        if (permission.granted && Manifest.permission.CAMERA.equals(permission.name)) {
                            // 用户已经同意该权限
                            ImagePicker imagePicker = new ImagePicker()
                                    .pickType(ImagePickType.SINGLE)//设置选取类型(拍照、单选、多选)
                                    .maxNum(1)//设置最大选择数量(拍照和单选都是1，修改后也无效)
                                    .needCamera(true)//是否需要在界面中显示相机入口(类似微信)
                                    .displayer(new GlideImagePickerDisplayer())//自定义图片加载器，默认是Glide实现的,可自定义图片加载器
                                    // .doCrop(1, 1, 300, 300)
                                    ;
                            //.start(AddWXFragment.this, code);

                            Intent intent = new Intent(getActivity(), ImageDataActivity.class);
                            intent.putExtra(ImageContants.INTENT_KEY_OPTIONS, imagePicker.getOptions());
                            startActivityForResult(intent, code);
                        }
                    }
                });
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.e("TAG","==========imageUrl========1111======");
        if (resultCode == Activity.RESULT_OK && data != null) {
            List<ImageBean> resultList = data.getExtras().getParcelableArrayList(ImagePicker.INTENT_RESULT_DATA);
            String imageUrl = "";
            if (resultList != null && resultList.size() > 0) {
                imageUrl = resultList.get(0).getImagePath();
                Log.e("TAG","==========imageUrl=============="+imageUrl);

//                GlideUtils.getInstances().loadNormalImg(getActivity(),binding.addImg,imageUrl);
            }
            if (requestCode == Constants.INTENT_REQUESTCODE_VERIFIED_IMG1) {
//                uploadImg(imageUrl, 1);
            }

        }
    }


    private CustomPopWindow mCustomPopWindow;
    private void popFuKuan(View view,String url)
    {
        View contentView = LayoutInflater.from(getContext()).inflate(R.layout.pop_fukuan_img,null);
        contentView.findViewById(R.id.fukuan_img).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mCustomPopWindow.dissmiss();
            }
        });
        GlideUtils.getInstances().loadNormalImg(getContext(),contentView.findViewById(R.id.fukuan_img),url);
        //创建并显示popWindow
        mCustomPopWindow = new CustomPopWindow.PopupWindowBuilder(getContext())
                .setView(contentView)
                .enableBackgroundDark(true) //弹出popWindow时，背景是否变暗
                .setBgDarkAlpha(0.3f) // 控制亮度
                .setFocusable(true)
                .setOutsideTouchable(true)
//                .size(600,400) //设置显示的大小，不设置就默认包裹内容
                .size(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)//显示大小
                .create()
                .showAtLocation(view, Gravity.CENTER,0,20);
//                .showAsDropDown(view,0,20);
    }

    private CustomPopWindow mCustomPopWindow2;
    private void selectPayType(View view)
    {
        if(mTransactionOrderEntity == null)
        {
            return;
        }

        View contentView = LayoutInflater.from(getContext()).inflate(R.layout.pop_select_paytype,null);

        RelativeLayout ll_bank = contentView.findViewById(R.id.ll_bank);
        RelativeLayout ll_zfb = contentView.findViewById(R.id.ll_zfb);
        RelativeLayout ll_wx = contentView.findViewById(R.id.ll_wx);
        ll_bank.setVisibility(View.GONE);
        ll_zfb.setVisibility(View.GONE);
        ll_wx.setVisibility(View.GONE);
        List<TransactionOrderEntity.SellerPay> listSellerPay = mTransactionOrderEntity.sellerPays.data;
//        mTransactionOrderEntity.pay_types
        String payTypes = "";
        if(mTransactionOrderEntity.pay_types != null && mTransactionOrderEntity.pay_types.size() > 0)
        {
            for(String paytype : mTransactionOrderEntity.pay_types)
            {
                payTypes = payTypes + paytype;
            }
        }
        for(TransactionOrderEntity.SellerPay sellerPay : listSellerPay)
        {
            if(payTypes.contains(sellerPay.type+""))
            {
                if(sellerPay.type == 1)
                {
                    ll_bank.setVisibility(View.VISIBLE);
                }
                else if(sellerPay.type == 2)
                {
                    ll_zfb.setVisibility(View.VISIBLE);
                }
                else if(sellerPay.type == 3)
                {
                    ll_wx.setVisibility(View.VISIBLE);
                }
            }
        }
        MCheckBox mcb_bank = contentView.findViewById(R.id.mcb_bank);
        MCheckBox mcb_zfb = contentView.findViewById(R.id.mcb_zfb);
        MCheckBox mcb_wx = contentView.findViewById(R.id.mcb_wx);

        contentView.findViewById(R.id.ll_bank).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dataSellerPay = getSellerPay(mTransactionOrderEntity,"1");
                setPayType(mTransactionOrderEntity,"1");
                mCustomPopWindow2.dissmiss();
                mcb_bank.setChecked(true);
                mcb_zfb.setChecked(false);
                mcb_wx.setChecked(false);
            }
        });
        contentView.findViewById(R.id.ll_zfb).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dataSellerPay = getSellerPay(mTransactionOrderEntity,"2");
                setPayType(mTransactionOrderEntity,"2");
                mCustomPopWindow2.dissmiss();
                mcb_bank.setChecked(false);
                mcb_zfb.setChecked(true);
                mcb_wx.setChecked(false);
            }
        });
        contentView.findViewById(R.id.ll_wx).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dataSellerPay = getSellerPay(mTransactionOrderEntity,"3");
                setPayType(mTransactionOrderEntity,"3");
                mCustomPopWindow2.dissmiss();
                mcb_bank.setChecked(false);
                mcb_zfb.setChecked(false);
                mcb_wx.setChecked(true);
            }
        });

        //创建并显示popWindow
        mCustomPopWindow2 = new CustomPopWindow.PopupWindowBuilder(getContext())
                .setView(contentView)
                .enableBackgroundDark(true) //弹出popWindow时，背景是否变暗
                .setBgDarkAlpha(0.3f) // 控制亮度
                .setFocusable(true)
                .setOutsideTouchable(true)
//                .size(600,400) //设置显示的大小，不设置就默认包裹内容
                .size(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)//显示大小
                .create()
                .showAtLocation(view, Gravity.BOTTOM,0,20);
//                .showAsDropDown(view,0,20);
    }
}